
#ifndef _MEMBER_BPARTICAL_H_
#define _MEMBER_BPARTICAL_H_

#include <BLine>
#include <BParticle>
#include "ITriangleCallback.h"

#define particle_member(particle)		((member_BParticle*)((BParticle*)particle)->_ptr)

namespace BWE
{
	class member_BParticle
	{
		friend class BParticle;

		struct Node
		{
			BSpace	space;
			BVector	center;
			int		index = -1;
		};
		typedef BArray<Node> NodeArray;

	public:
		member_BParticle(BParticle* particle);
		~member_BParticle();

		void build(BMesh* mesh, const BSpace& space);
		void buildTree(int startIndex, int endIndex);

		void overlapping(ITriangleCallback* callback, const BSpace& space) const;
		void overlapping(ITriangleCallback* callback, const BLine& line) const;

		BParticle*			boss;
		BRealSize			size;
		int					particleDuration;
		int					emitterDuration;
		BArray<BVector>		points;
		BHolder<BByteArray>	pixels;
		bool				dirty;

		BSpace				m_space;
		int					lastIndex;
		NodeArray			leafNodes;
		NodeArray			treeNodes;
		mutable int			m_processCount;

	};
}

#endif